package com.fitz.remote.client.pool;

import com.fitz.registry.InstanceInfo;
import com.fitz.remote.client.ConsumerClient;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author fitz
 * Created  on 2020/5/26
 */
public class PoolTest {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        InstanceInfo node = new InstanceInfo();
        node.setHost("127.0.0.1");
        node.setPort(7776);
        ConsumerClientPool proxy = new ConsumerClientPool(node,5,10);
        if (!proxy.connect()){
            System.out.println("connect server fail --------> 1");
            return;
        }
        for (int i = 1; i <= 500; i++){
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    ConsumerClient client = proxy.getClient();
                    System.out.println(client);
                    proxy.returnClient(client);
                }
            });
        }
        System.out.println("return:"+proxy.getNumIdle());
    }
}
